<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Responsive Admin Dashboard Template">
    <meta name="keywords" content="admin,dashboard">
    <meta name="author" content="skcats">
    <title>工作经历</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
</head>
<body>
<div style="margin-left: 20px" class="demo-tree" id="test"></div>
</body>
<script th:src="@{/assets/plugins/jquery/jquery-3.1.0.min.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:inline="none">
    layui.use(['tree', 'util'], function() {
        var tree = layui.tree
            , layer = layui.layer
            , util = layui.util

        $.ajax({
            type: "post",
            url: "/jurisdiction/atreedata",
            dataType: 'json',
            async: true,//是否异步请求
            success: function (data) {
                layui.use('tree', function () {
                    //开启复选框
                    tree.render({
                        elem: '#test'
                        ,id: 'demo'
                        ,data: data
                        ,showCheckbox: true
                        ,oncheck: function(obj){
                            if (obj.checked){
                                $.ajax({
                                    type: "post",
                                    url: "/jurisdiction/add",
                                    dataType: 'json',
                                    async: true,//是否异步请求
                                    data:{
                                        id:obj.data.id
                                    }
                                })
                            }else {
                                $.ajax({
                                    type: "post",
                                    url: "/jurisdiction/del",
                                    dataType: 'json',
                                    async: true,//是否异步请求
                                    data:{
                                        id:obj.data.id
                                    }
                                })
                            }
                        }
                    });
                })
            }
        })
    })
</script>
</html>